<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>修改个人信息</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <link rel="shortcut icon" href="../img/favicon.ico">

    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="../plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="../plugins/morris/morris.css">
    <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="../plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="../plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="../plugins/select2/select2.css">
    <link rel="stylesheet" href="../plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="../plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="../plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="../plugins/bootstrap-start/css/star-rating.css" media="all" rel="stylesheet"
          type="text/css">
    <style>
        /* tab 1*/
        .double {
            line-height: 58px;
        }
        .title .glyphicon{
            padding: 3px;
            font-size: 13px;
            border-radius: 8px;
            color: #fff;

        }
        .data span.arrowup {
            color: #d88918;
        }
        .data span.arrowdown {
            color: #6bb10a;
        }
        .item-blue .glyphicon{
            background-color: #39a9ea;
        }
        .item-green {
            line-height: 58px;
        }
        .item-green .glyphicon{
            background-color: #6bb10a;
            line-height: 12px;
        }
        .item-orange .glyphicon{
            background-color:#d88918;
        }
        .item-red .glyphicon{
            background-color: #f14f4f;
        }
        .chart .chart-box {
            margin: 10px;
        }

        /* 数据表格label */
        .content-wrapper .data-type {
            /*width: 90%;*/
            margin: 10px 5px;
            border:1px solid #d4d4d4;
            border-radius: 2px;
        }
        .data-type .title,
        .data-type .data {
            padding: 3px 12px;
            border-top: 1px solid #d4d4d4;
            overflow: hidden;
            height: 42px;
        }
        .data-type .title {
            line-height: 34px;
            border-right: 1px solid #d4d4d4;
        }

        .data-type .data:last-child{
            border-right: 0;
        }
        .data-type .title{
            text-align: center;
            background: #ececec;
        }
        .data-type .data .line{
            vertical-align: middle;
            overflow: hidden;
            padding-bottom: 10px;
            padding-top: 10px;
        }

        /* label行高度 */
        .data-type .data > label {
            line-height:36px;
        }
        .data-type .data > .form-group {
            line-height:36px;
        }
        .data-type .data.text {
            line-height:36px;
        }
        /* label行分隔符 */
        .data-type .data.border-right {
            border-right: 1px solid #d4d4d4;
        }

        /* 表格双倍高度 */
        .data-type .title.rowHeight2x,
        .data-type .data.rowHeight2x {
            height:84px;
        }
        .data-type .title.rowHeight2x ,
        .data-type .data.rowHeight2x.text {
            line-height:78px;
        }

        /* 表格双倍高度 */
        .data-type .title.rowHeight4x,
        .data-type .data.rowHeight4x {
            height:150px;
        }

        /*.data-type .data.rowHeight2x > label {
            line-height:78px;
        }*/
        .data-type .title.editer,
        .data-type .data.editer {
            height:320px;
        }
        .data-type .title.editer {
            line-height:300px;
        }

        /*清除padding*/
        .padding-clear {
            padding-right: 0px;
            padding-left: 0px;
        }

        /* 文件上传 */
        /*a  upload */
        .a-upload {
            padding: 4px 10px;
            height: 35px;
            line-height: 25px;
            position: relative;
            cursor: pointer;
            color: #888;
            background: #fafafa;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }
        .a-upload  input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        .a-upload:hover {
            color: #444;
            background: #eee;
            border-color: #ccc;
            text-decoration: none
        }
        /*个人信息代码*/
        .icon-title{
            display: flex;
            flex-direction: row;
            align-items: center;
            width: 95%;
            margin: 20px auto 0;
        }
        .icon-title .title{
            font-weight: 600;
        }
        .msg-title{
            background: transparent !important;
            border: none !important;
            padding: 0 !important;
            line-height: 42px !important;
            margin-left: 10px;
        }
        .icon-title+.data{
            background: #ffffff;
            width: 95%;
            margin: 0px auto !important;
            border-radius: 15px;
        }
        .upload-img{
            width: 120px;
            height: 120px;
            margin-left: 30px;
            border-radius: 10px;
            background: #ffffff;
            overflow: hidden;
        }
        .upload-img img{
            width: 100%;
            height: 100%;
            float: left;
        }
        .data-type{
            padding-bottom: 20px;
        }
        .data-type-update>div{
            width: 95%;
            padding: 0 !important;
            margin: 0px auto;
            border: none !important;
        }
        .data-type-update .title{
            font-weight: 600;
            text-align: start;
            background: transparent;
            margin-top: 15px;
        }
        /*上传图片按钮组件样式*/
        .upload-group{
            display: flex;
            flex-direction: column;
            margin: 20px 0;
        }
        .upload-group img{
            margin-top: 10px;
            width: 120px;
            height: 120px;
            border-radius: 10px;
        }



    </style>
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper info">

    <!-- 头部+导航侧栏 -->
    <div id="page-head"></div>
    <!-- 头部+导航侧栏  /-->

    <!-- 内容区域 -->
    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1 style="padding: 0 12px">
                个人信息
                <small>修改信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="all-order-manage-list.html">我的个人</a></li>
                <li class="active">修改信息</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!--个人信息-->
            <div class="">
                <div class="data-type data-type-update">

                    <input type="text" id="userId" style="display: none"></input>
                    <div class="title">个人姓名</div>
                    <div class="data text input-data" id="houseOwner">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-tag"></i>
                            </div>
                            <input type="text" id="userName" class="form-control pull-right" placeholder="请输入姓名"
                                   value="">
                        </div>
                    </div>

                    <div class="title">个人地址</div>
                    <div class="data text input-data" id="houseAddress">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-map-marker"></i>
                            </div>
                            <input type="text" id="userAddress" class="form-control pull-right" placeholder="请输入地址"
                                   value="">

                        </div>
                    </div>

                    <div class="title">性别</div>
                    <div class="data text input-data" id="houseUnitHeight">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-adjust"></i>
                            </div>
                            <input type="text" id="userUnitHeight" class="form-control pull-right" placeholder="请输入性别"
                                   value="">
                        </div>
                    </div>

                    <div class="title">电话</div>
                    <div class="data text input-data" id="houseArea">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-phone"></i>
                            </div>
                            <input type="text" id="userArea" class="form-control pull-right" placeholder="请输入电话"
                                   value="">

                        </div>
                    </div>

                    <div class=" title">邮箱</div>
                    <div class="input-data data text" id="houseType">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-envelope"></i>
                            </div>
                            <input type="text" id="userType" class="form-control pull-right" placeholder="请输入邮箱"
                                   value="">

                        </div>
                    </div>

                    <div class="title">修改密码</div>
                    <div class="input-data data text">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-lock"></i>
                            </div>
                            <input type="password" id="userPassword" class="form-control pull-right"
                                   placeholder="请输入密码（选填）"
                                   value="">

                        </div>
                    </div>

                </div>

                <!--                    图片上传功能-->
                <div class="upload-group">
                    <button href="javascript:void(0)" onclick="uploadPhoto()" class="btn btn-success" style="width:100px;">上传头像</button>
                    <input type="file" id="photoFile" style="display: none;" onchange="upload()">
                    <img id="preview_photo" class="img-thumbnail" src="../img/default-avatar.png" name="image" width="200px" height="200px">
                </div>
            </div>

            <!--个人信息/-->

            <button type="button" id="sendUserHouse" class="btn bg-maroon save-btn">保存</button>
            <button type="button" class="btn btn-info back-btn" onclick="history.back(-1);"
                    style="background: rgb(96,92,168);margin-left: 10px">返回
            </button>

        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- 内容区域 /-->

    <!-- 底部导航 -->
    <div id="page-footer"></div>
    <!-- 底部导航 /-->

</div>


<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/raphael/raphael-min.js"></script>
<script src="../plugins/morris/morris.min.js"></script>
<script src="../plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="../plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="../plugins/knob/jquery.knob.js"></script>
<script src="../plugins/daterangepicker/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="../plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="../plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="../plugins/fastclick/fastclick.js"></script>
<script src="../plugins/iCheck/icheck.min.js"></script>
<script src="../plugins/adminLTE/js/app.min.js"></script>
<script src="../plugins/treeTable/jquery.treetable.js"></script>
<script src="../plugins/select2/select2.full.min.js"></script>
<script src="../plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="../plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="../plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="../plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="../plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="../plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="../plugins/ckeditor/ckeditor.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="../plugins/chartjs/Chart.min.js"></script>
<script src="../plugins/flot/jquery.flot.min.js"></script>
<script src="../plugins/flot/jquery.flot.resize.min.js"></script>
<script src="../plugins/flot/jquery.flot.pie.min.js"></script>
<script src="../plugins/flot/jquery.flot.categories.min.js"></script>
<script src="../plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="../plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="../plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="../plugins/bootstrap-start/js/star-rating.js"></script>
<script>
    function uploadPhoto() {
        $("#photoFile").click();
    }

    /**
     * 上传图片
     */
    function upload() {
        if ($("#photoFile").val() == '') {
            return;
        }
        var formData = new FormData();
        formData.append('photo', document.getElementById('photoFile').files[0]);
        $.ajax({
            url: "/userHeadUpload",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data.type == "success") {
                    console.log("图片上传后端数据响应成功！")
                    $("#preview_photo").attr("src", data.filepath + data.filename);
                    $("#preview_photo").attr("name", data.filename);

                } else {
                    alert(data.msg);
                }
            },
            error: function (data) {
                alert("上传失败")
            }
        });
    }
</script>
<script>
    $(document).ready(function () {
        //装入头部
        $('#page-head').load('public-head.html', null, function () {
            setSidebarActive("admin-update");
        });
        //装入尾部
        $('#page-footer').load('public-footer.html');
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function () {
        $('#datepicker-a3').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });


    $(document).ready(function () {
        $('#datepicker-a6').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });
</script>
<script>
    $(function () {
        var userData = "";  //保存的是当前个人的基本信息
        //填充个人基本信息表格数据
        function handleuserData() {
            if (userData !== "") {
                $("#userId").attr("value", userData.id); //改姓名
                $("#userName").attr("value", userData.userName); //改姓名
                $("#userAddress").attr("value", userData.address); //改地址
                $("#userUnitHeight").attr("value", userData.sex); //改性别
                $("#userArea").attr("value", userData.tel); //改电话
                $("#userType").attr("value", userData.mail); //改邮箱
                window.userpassword = userData.userPassword;
                // $("#userPassword").attr("value", userData.userPassword); //改密码
                if (userData.headImage != undefined && userData.headImage != "") {
                    $("#preview_photo").attr("src", "../headImage/" + userData.headImage);
                    $("#preview_photo").attr("name", userData.headImage);
                } else {
                    console.log("该用户没有头像！")
                    $("#preview_photo").attr("src", "../img/" + "user-head.png");
                }
            } else {
                alert("获取用户信息失败，请联系工作人员！")
            }


        }

        //获取当前用户的信息
        $.ajax({
            url: "/all-order-manage-edit/message/user",   //请求路径
            type: "get",    //请求方式
            dataType: "json",  //设置接收到数据类型
            success: function (data) {
                console.log("返回的用户信息:" + data);
                userData = JSON.parse(data);
                handleuserData();   //处理请求
                // 处理分页数据
            },    //成功
            error: function () {
                console.log("获取姓名失败...")
            }
        })


    })


</script>
<script>
    $(function () {
        // 禁用历史表单填充
        $("input").attr("autocomplete", "off");

        var userData = "";  //保存旧的json数据

        var id = "";

        var userName = "";     //保存个人姓名
        var address = "";       //保存地址
        var sex = "";      //保存性别
        var tel = "";           //保存电话号码
        var mail = "";              //保存邮箱
        var password = "";    //存储密码
        var preview_photo = "";    //存储密码
        //更新时间也需要修改

        //判断用户输入是否合法
        function isLegal() {
            if (userName === "") {
                alert("请输入个人的姓名");
                return false;
            }
            if (address === "") {
                alert("请输入地址");
                return false;
            }
            if (sex === "") {
                alert("请输入性别");
                return false;
            }
            if (tel === "") {
                alert("请输入个人电话");
                return false;
            }
            if (mail === "") {
                alert("请输入个人邮箱");
                return false;
            }
            if (id === "") {
                alert("后台获取出现错误，请联系工作人员")
            }
            if (password === "") {
                password = window.userpassword;
            }
            return true;
        }


        $("#sendUserHouse").on("click", function () {
            id = $("#userId").val();                  //保存个人id
            userName = $("#userName").val();                  //保存个人姓名
            address = $("#userAddress").val();                 //保存地址
            sex = $("#userUnitHeight").val();        //保存性别
            tel = $("#userArea").val();                  //保存电话
            mail = $("#userType").val();                    //保存邮箱
            password = $("#userPassword").val();                    //保存密码
            preview_photo = $("#preview_photo").attr("name");      //获取图片

            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "H+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            var myDate = new Date().Format("yyyy-MM-dd HH:mm:ss");  //时间

            //先ajax的post请求发送给后台存储
            //先判断合法性
            if (isLegal()) {
                // alert("输入合法！");
                //包装成json数据
                var dataJson = {
                    "userId": id,
                    "userName": userName,     //保存个人姓名
                    "address": address,     //保存地址
                    "sex": sex,  //保存性别
                    "tel": tel,           //保存电话号码
                    "mail": mail,              //保存邮箱
                    "updateTime": myDate,
                    "userPassword": password,
                    "headImage": preview_photo
                };
                //ajax请求,通过post返回给后台存储
                $.ajax({
                    url: "/user-update/user/update",   //请求路径
                    type: "post",    //请求方式，这里应该用post，返回给后台分页是数据：当前页，每页的大小
                    data: JSON.stringify(dataJson),
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",  //设置接收到数据邮箱
                    success: function (data) {
                        alert("保存成功！");
                        // 处理分页数据
                        // console.log("个人存储信息增加成功！");
                    },    //成功
                    error: function () {
                        console.log("个人存储信息失败...")
                    }
                })
            }


        })


        // //（！！！需要修改）获取当前用户的id
        // $.ajax({
        //     url: "/all-order-manage-edit/message/user",   //请求路径
        //     type: "get",    //请求方式
        //     dataType: "json",  //设置接收到数据邮箱
        //     success: function (data) {
        //         userData = JSON.parse(data);
        //         id = userData.id;
        //         console.log(userData);
        //
        //         // 处理分页数据
        //     },    //成功
        //     error: function () {
        //         console.log("获取用户信息失败...")
        //     }
        // })


    })


</script>
</body>

</html>